/********************************************************************************************************************
** Contact: yashvpatil@gmail.com
**
** GNU General Public License Usage
** This file may be used under the terms of the GNU
** General Public License versions 2.0 or 3.0 as published by the Free Software Foundation.
** Please review the following information to ensure GNU General Public Licensing requirements will be met:
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
*********************************************************************************************************************/

#include "testwidget.h"

CTestWidget::CTestWidget(QWidget *parent):QWidget(parent)
{
	layout = NULL;

	rw = NULL;
	rw1 = NULL;
	rw2 = NULL;
	rw3 = NULL;

	rw4 = NULL;
	rw5 = NULL;
	rw6 = NULL;
	rw7 = NULL;

	lbl_rw = NULL;
	lbl_rw1 = NULL;
	lbl_rw2 = NULL;
	lbl_rw3 = NULL;
	lbl_rw4 = NULL;
	lbl_rw5 = NULL;
	lbl_rw6 = NULL;
	lbl_rw7 = NULL;


	layout = new QGridLayout();

	rw = new QRangeWidget_Arc(10, 10, this);
	rw1 = new QRangeWidget_Arc(50, 10, this);
	rw2 = new QRangeWidget_Arc(90, 10, this);
	rw3 = new QRangeWidget_Arc(130, 10, this);


	rw4 = new QRangeWidget_Bar(10, 70, this);
	rw5 = new QRangeWidget_Bar(80, 70, this);
	rw6 = new QRangeWidget_Bar(160, 70, this);
	rw7 = new QRangeWidget_Bar(230, 70, this);

	lbl_rw = new QLabel("ARC 1\nLeft to Right", this);
	lbl_rw1 = new QLabel("ARC 2\nTop to Bottom", this);
	lbl_rw2 = new QLabel("ARC 3\nRight to Left", this);
	lbl_rw3 = new QLabel("ARC 4\nBottom to Top", this);
	lbl_rw4 = new QLabel("BAR 1\nLeft to Right", this);
	lbl_rw5 = new QLabel("BAR 2\nTop to Bottom", this);
	lbl_rw6 = new QLabel("BAR 3\nRight to Left", this);
	lbl_rw7 = new QLabel("BAR 4\nBottom to Top", this);


	if (rw) rw->setBackColor(QColor(0,0,0));
	if (rw1) rw1->setBackColor(QColor(0,0,0));
	if (rw2) rw2->setBackColor(QColor(0,0,0));
	if (rw3) rw3->setBackColor(QColor(0,0,0));

	if (rw4) rw4->setBackColor(QColor(0,0,0));
	if (rw5) rw5->setBackColor(QColor(0,0,0));
	if (rw6) rw6->setBackColor(QColor(0,0,0));
	if (rw7) rw7->setBackColor(QColor(0,0,0));


	if (rw) rw->setForeColor(QColor(255, 0, 0));
	if (rw1) rw1->setForeColor(QColor(0, 255, 0));
	if (rw2) rw2->setForeColor(QColor(0, 0, 255));
	if (rw3) rw3->setForeColor(QColor(0, 255, 255));

	if (rw4) rw4->setForeColor(QColor(255, 255, 255));
	if (rw5) rw5->setForeColor(QColor(255, 255, 0));
	if (rw6) rw6->setForeColor(QColor(255, 0,255));
	if (rw7) rw7->setForeColor(QColor(0, 255, 0));

	if (rw) rw->setPenWidth(1);
	if (rw1) rw1->setPenWidth(2);
	if (rw2) rw2->setPenWidth(3);
	if (rw3) rw3->setPenWidth(4);

	if (rw4) rw4->setPenWidth(1);
	if (rw5) rw5->setPenWidth(2);
	if (rw6) rw6->setPenWidth(3);
	if (rw7) rw7->setPenWidth(4);

	if (rw) rw->setOrientation(QRangeWidget::HORIZONTAL);
	if (rw1) rw1->setOrientation(QRangeWidget::VERTICAL);
	if (rw2) rw2->setOrientation(QRangeWidget::HORIZONTAL_R);
	if (rw3) rw3->setOrientation(QRangeWidget::VERTICAL_R);


	if (rw4) rw4->setOrientation(QRangeWidget::HORIZONTAL);
	if (rw5) rw5->setOrientation(QRangeWidget::VERTICAL);
	if (rw6) rw6->setOrientation(QRangeWidget::HORIZONTAL_R);
	if (rw7) rw7->setOrientation(QRangeWidget::VERTICAL_R);

	rw->setFixedSize(32, 27);
	rw1->setFixedSize(32, 27);
	rw2->setFixedSize(32, 27);
	rw3->setFixedSize(32, 27);
	rw4->setFixedSize(32, 27);
	rw5->setFixedSize(32, 27);
	rw6->setFixedSize(32, 27);
	rw7->setFixedSize(32, 27);


	layout->addWidget(rw, 0, 0);
	layout->addWidget(rw1, 0, 1);
	layout->addWidget(rw2, 0, 2);
	layout->addWidget(rw3, 0, 3);

	layout->addWidget(lbl_rw, 1, 0);
	layout->addWidget(lbl_rw1, 1, 1);
	layout->addWidget(lbl_rw2, 1, 2);
	layout->addWidget(lbl_rw3, 1, 3);

	layout->addWidget(rw4, 2, 0);
	layout->addWidget(rw5, 2, 1);
	layout->addWidget(rw6, 2, 2);
	layout->addWidget(rw7, 2, 3);

	layout->addWidget(lbl_rw4, 3, 0);
	layout->addWidget(lbl_rw5, 3, 1);
	layout->addWidget(lbl_rw6, 3, 2);
	layout->addWidget(lbl_rw7, 3, 3);


	setLayout(layout);

	timer.setInterval(200);
	timer.start();

	timer1.setInterval(1000);
	timer1.start();

	connect(&timer, SIGNAL(timeout()), this, SLOT(timerslot()));
	connect(&timer1, SIGNAL(timeout()), this, SLOT(timerslot1()));

	setWindowTitle("Sample App - Current Range : ");

	show();
}


CTestWidget::~CTestWidget()
{
	if (rw7) delete rw7;
	if (rw6) delete rw6;
	if (rw5) delete rw5;
	if (rw4) delete rw4;


	if (rw3) delete rw3;
	if (rw2) delete rw2;
	if (rw1) delete rw1;
	if (rw) delete rw;

	if (lbl_rw7) delete lbl_rw7;
	if (lbl_rw6) delete lbl_rw6;
	if (lbl_rw5) delete lbl_rw5;
	if (lbl_rw4) delete lbl_rw4;
	if (lbl_rw3) delete lbl_rw3;
	if (lbl_rw2) delete lbl_rw2;
	if (lbl_rw1) delete lbl_rw1;
	if (lbl_rw) delete lbl_rw;


	if (layout) delete layout;

}

void CTestWidget::timerslot()
{
	int i = qrand() % (6);

	if (rw) rw->setLevel((QRangeWidget::Level)i);
	if (rw1) rw1->setLevel((QRangeWidget::Level)i);
	if (rw2) rw2->setLevel((QRangeWidget::Level)i);
	if (rw3) rw3->setLevel((QRangeWidget::Level)i);

	if (rw4) rw4->setLevel((QRangeWidget::Level)i);
	if (rw5) rw5->setLevel((QRangeWidget::Level)i);
	if (rw6) rw6->setLevel((QRangeWidget::Level)i);
	if (rw7) rw7->setLevel((QRangeWidget::Level)i);
}

void CTestWidget::timerslot1()
{
	QString s;

	int i = (int) rw->currentRange(s);

	setWindowTitle("Sample App - Current Range : "+ s);
}
